這次使用的是VM VirtualBox架設Ubuntu20.04進行實驗。
kubectl apply -f mysql_deployment.yaml
kubectl apply -f mysql_service.yaml
結果:
user@user-VirtualBox:~/Downloads$ kubectl apply -f mysql_deployment.yaml
deployment.apps/mysql-deployment created
user@user-VirtualBox:~/Downloads$ kubectl apply -f mysql_service.yaml
service/mysql-service created
kubectl get all
確認Pod的STATUS為Running
結果:
user@user-VirtualBox:~/Downloads$ kubectl get all
NAME                                    READY   STATUS    RESTARTS   AGE
pod/mysql-deployment-78844774d7-pwsv7   1/1     Running   0          14m
NAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
service/kubernetes      ClusterIP   10.96.0.1       <none>        443/TCP          25m
service/mysql-service   NodePort    10.106.22.143   <none>        3306:30306/TCP   14m
NAME                               READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/mysql-deployment   1/1     1            1           14m
NAME                                          DESIRED   CURRENT   READY   AGE
replicaset.apps/mysql-deployment-78844774d7   1         1         1       14m
因為我們使用Service把Pod內的MySql使用NodePort的方式轉出來了,所以要連接的port號為你設定的。
mysql -h localhost -P 30306 --protocol=tcp -u root -p
結果:
user@user-VirtualBox:~/Downloads$ mysql -h localhost -P 30306 --protocol=tcp -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>  
Command 'mysql' not found, but can be installed with:
sudo apt install mysql-client-core-8.0     # version 8.0.30-0ubuntu0.20.04.2, or
sudo apt install mariadb-client-core-10.3  # version 1:10.3.34-0ubuntu0.20.04.1
明天會介紹MySql的使用者設定與資料庫匯入,各位明天見~